package com.ukefu.util.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.corundumstudio.socketio.SocketIOServer;
import com.ukefu.core.UKDataContext;
import com.ukefu.util.server.handler.AgentEventHandler;
import com.ukefu.util.server.handler.IMEventHandler;
  
@Component  
public class ServerRunner implements CommandLineRunner {  
    private final SocketIOServer server;  
    
    private IMEventHandler imEventHandler ;
    
    private AgentEventHandler agentEventHandler ;
    
    @Autowired  
    public ServerRunner(SocketIOServer server , IMEventHandler imEventHandler , AgentEventHandler agentEventHandler) {  
        this.server = server;  
        this.imEventHandler = imEventHandler ;
        this.agentEventHandler = agentEventHandler ;
    }  
  
    public void run(String... args) throws Exception { 
    	server.getNamespace(UKDataContext.NameSpaceEnum.IM.toString()).addListeners(imEventHandler);
    	server.getNamespace(UKDataContext.NameSpaceEnum.AGENT.toString()).addListeners(agentEventHandler);
        server.start();  
    }  
}  